<template>
	<div class="white-box">

		<div class="task-one">
			<div class="task-one__item">
				<span class="task-one__label">会员uid：</span>
				<el-input placeholder="请输入会员uid搜索" v-model="uid" @keyup.enter.native="handleSearch" clearable>
				</el-input>
			</div>
			<div class="task-one__item">
				<span class="task-one__label">会员名称：</span>
				<el-input placeholder="请输入会员名称搜索" v-model="search_text" @keyup.enter.native="handleSearch" clearable>
				</el-input>
			</div>
			<div class="task-one__item">
				<span class="task-one__label">手机号：</span>
				<el-input placeholder="请输入手机号搜索" v-model="phone" @keyup.enter.native="handleSearch" clearable>
				</el-input>
			</div>
			<div class="task-one__item">
				<span class="task-one__label">核销员：</span>
				<el-select v-model="is_verifier" clearable placeholder="请选择是否核销员">
					<el-option label="是" :value="1" />
					<el-option label="否" :value="0" />
				</el-select>
			</div>
			<div class="task-one__item">
				<span class="task-one__label">分销商：</span>
				<el-select v-model="is_distributor" clearable placeholder="请选择是否分销商">
					<el-option label="是" :value="1" />
					<el-option label="否" :value="0" />
				</el-select>
			</div>
			<div class="task-one__btn clearfix">
				<el-button type="primary" :loading="search_btn" :icon="Search" @click="handleSearch">搜索</el-button>
			</div>
		</div>

		<el-table class="table-mb" v-loading="loading" :data="arr_data" :header-cell-style="{ background: '#F5F7FA' }"
			element-loading-background="rgba(255, 255, 255, 0.6)" @selection-change="handleAllSelected" @sort-change="sortTab">
			<!-- <el-table-column type="selection" width="55" /> -->
			<el-table-column prop="store_name" label="会员" width="100">
				<template #default="{ row }">
					<el-image class="user_logo" lazy :src="proxy.imgUrl + row.user_logo" fit="cover"
						v-if="row.user_logo" />
					<el-avatar v-else :size="60"
						src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png" />
				</template>
			</el-table-column>
			<el-table-column prop="store_img" label="基本信息">
				<template #default="{ row }">
					<div>
						<div>ID:{{row.id}}</div>
						<div>{{row.user_name}}<span v-if="row.is_rider==2">(骑手)</span></div>
						<div v-if="row.level>0">会员等级:{{row.level_label.label}}</div>
						<div>{{row.phone}}</div>
						<div>{{row.nation}}</div>
						<div v-if="row.invite_user.length!=0">上级ID:{{row.invite_user.id}}</div>
						<div v-if="row.invite_user.length!=0">上级昵称:{{row.invite_user.user_name}}</div>
					</div>
				</template>
			</el-table-column>
			<el-table-column prop="integral_balance" label="余额">
				<template #default="{ row }">
					<div>
						<div>积分：{{row.integral_balance}}</div>
						<div>钱包：￥{{row.wallet_balance}}</div>
						<div>佣金：￥{{row.commission}}</div>
					</div>
				</template>
			</el-table-column>
			<el-table-column prop="total" label="消费" sortable='custom'>
				<template #default="{ row }">
					<div>
						<div>￥{{row.total}}</div>
					</div>
				</template>
			</el-table-column>
			<el-table-column prop="is_verifier" label="核销员" width="170">
				<template #default="{ row }">
					<div>
						<el-radio-group v-model="row.is_verifier" size="small" @change="changeVerifier(row,$event)">
							<el-radio-button :label="1">是</el-radio-button>
							<el-radio-button :label="0">否</el-radio-button>
						</el-radio-group>
					</div>
				</template>
			</el-table-column>
			<el-table-column prop="is_distributor" label="分销商" width="170">
				<template #default="{ row }">
					<div>
						<el-radio-group v-model="row.is_distributor" size="small"
							@change="changeDistributor(row,$event)">
							<el-radio-button :label="1">是</el-radio-button>
							<el-radio-button :label="0">否</el-radio-button>
						</el-radio-group>
					</div>
				</template>
			</el-table-column>
			<el-table-column prop="created_at" label="注册时间"  sortable='custom'></el-table-column>
			<el-table-column label="操作" width="270" fixed="right">
				<template #default="{ row }">
					<el-button class="theme-btn" link type="primary" @click="handleDetail(row)">详情</el-button>
					<el-button v-if="row.is_rider!=2" class="theme-btn" link type="primary"
						@click="handleRider(row)">设置骑手</el-button>
					<el-button class="theme-btn" link type="primary"
						@click="handleEdit(row,'wallet_balance')">调整余额</el-button>
					<el-button class="theme-btn" link type="primary"
						@click="handleEdit(row,'integral_balance')">调整积分</el-button>
					<el-button class="theme-btn" link type="primary" @click="handleCommission(row)">调整佣金</el-button>
					<el-button class="theme-btn" link type="primary" @click="handleLevel(row)">调整会员等级</el-button>
					<el-button class="theme-btn" link type="primary" @click="handleBind(row)">设置上级</el-button>
					<el-button class="theme-btn" link type="primary" @click="handleDownuser(row)">查看下级</el-button>
					<el-button class="theme-btn" link type="primary" @click="handleCoupon(row)">发放优惠券</el-button>
					<!-- <el-popconfirm :persistent="false" title="确定删除吗？" confirm-button-text="确定" cancel-button-text="取消"
						@confirm="handleDelete(row)">
						<template #reference>
							<el-button class="theme-btn" link type="primary" style="margin-left: 14px">删除</el-button>
						</template>
					</el-popconfirm> -->
				</template>
			</el-table-column>
		</el-table>

		<el-pagination background v-model:current-page="page" v-model:page-size="pageSize" :page-sizes="pageSizeNum"
			:total="totalNums" layout="total, sizes, prev, pager, next, jumper">
		</el-pagination>



		<go-back />

		<el-dialog v-model="showEditBalance" :title="ruleClassForm.balanceKey=='integral_balance'?'调整积分':'调整余额'"
			width="560px" :append-to-body="true" :destroy-on-close="true" :close-on-click-modal="false"
			@close="closeAddClass">
			<el-form ref="ruleClassRef" :model="ruleClassForm" :rules="ruleCheckClass" label-width="120px">
				<el-form-item label="会员ID" prop="balanceKey">
					<div>{{ruleClassForm.member_id}}</div>
				</el-form-item>
				<el-form-item v-if="ruleClassForm.balanceKey=='wallet_balance'" label="余额" prop="balanceKey">
					<div>{{ruleClassForm.wallet}}</div>
				</el-form-item>
				<el-form-item v-if="ruleClassForm.balanceKey=='integral_balance'" label="积分" prop="balanceKey">
					<div>{{ruleClassForm.integral}}</div>
				</el-form-item>

				<el-form-item label="变动类型" prop="type">
					<el-radio-group v-model="ruleClassForm.type">
						<el-radio :label="1">增加</el-radio>
						<el-radio :label="2">减少</el-radio>
					</el-radio-group>
				</el-form-item>

				<el-form-item label="变动" prop="balance" required>
					<el-input v-model.trim="ruleClassForm.balance" type="number" clearable placeholder="请输入余额变动" />
				</el-form-item>

				<el-form-item label="备注" prop="remark" required>
					<el-input v-model.trim="ruleClassForm.remark" :rows="2" type="textarea" clearable
						placeholder="请输入备注" />
				</el-form-item>
				<el-form-item>
					<div class="flexs" style="margin-top: 30px">
						<el-button type="primary" :loading="form_loading" @click="submitClassForm(ruleClassRef)">
							确认
						</el-button>
						<el-button @click="resetClassForm(ruleClassRef)">重置</el-button>
					</div>
				</el-form-item>
			</el-form>
		</el-dialog>

		<el-dialog v-model="showEditCommission" title="调整收益" width="560px" :append-to-body="true"
			:destroy-on-close="true" :close-on-click-modal="false" @close="closeAddCommission">
			<el-form ref="ruleCommissionRef" :model="ruleCommissionForm" :rules="ruleCheckCommission"
				label-width="120px">
				<el-form-item label="会员ID" prop="member_id">
					<div>{{ruleCommissionForm.member_id}}</div>
				</el-form-item>

				<el-form-item label="变动" prop="balance" required>
					<el-input v-model.trim="ruleCommissionForm.balance" type="number" clearable placeholder="请输入余额变动" />
					<div style="font-size: 14px;">正数增加，负数减少</div>
				</el-form-item>

				<el-form-item label="备注" prop="remark" required>
					<el-input v-model.trim="ruleCommissionForm.remark" :rows="2" type="textarea" clearable
						placeholder="请输入备注" />
				</el-form-item>
				<el-form-item>
					<div class="flexs" style="margin-top: 30px">
						<el-button type="primary" :loading="form_loading"
							@click="submitCommissionForm(ruleCommissionRef)">
							确认
						</el-button>
						<el-button @click="resetCommissionForm(ruleCommissionRef)">重置</el-button>
					</div>
				</el-form-item>
			</el-form>
		</el-dialog>

		<el-dialog v-model="showRider" title="骑手" width="1300px" :append-to-body="true" :destroy-on-close="true"
			:close-on-click-modal="false" @close="closeAddRider">
			<el-form ref="ruleRiderRef" :model="ruleRiderForm" :rules="ruleCheckRider" label-width="120px">
				<el-row>
					<el-col :span="12">
						<el-form-item label="会员ID" prop="balanceKey">
							<div>{{ruleRiderForm.member_id}}</div>
						</el-form-item>
						<el-form-item label="账号" prop="account" required>
							<el-input v-model.trim="ruleRiderForm.account" clearable placeholder="请输入账号" />
						</el-form-item>
						<el-form-item label="密码" prop="password" required>
							<el-input v-model.trim="ruleRiderForm.password" type="password" clearable
								name="current-password" autocomplete="new-password" placeholder="请输入密码" show-password />
						</el-form-item>
						<el-form-item label="姓名" prop="rider_name" required>
							<el-input v-model.trim="ruleRiderForm.rider_name" clearable placeholder="请输入姓名" />
						</el-form-item>
						<el-form-item label="手机号" prop="phone" required>
							<el-input v-model.trim="ruleRiderForm.phone" clearable placeholder="请输入手机号" />
						</el-form-item>
						<el-form-item label="身份证正面" prop="card_front" required>
							<div class="avatar-uploaderqishou" @click="onKey('card_front')">
								<el-upload ref="uploadFileRef" :show-file-list="false" :action="actionImgUrl()"
									:on-change="fileChange" :multiple="upload_batch" :auto-upload="false" :limit="1"
									style="margin-right: 12px">
									<img v-if="ruleRiderForm.card_front" :src="proxy.imgUrl + ruleRiderForm.card_front"
										class="avatar" />
									<el-icon v-else color="#999" class="avatar-uploader-icon">
										<upload-filled />
									</el-icon>
								</el-upload>
							</div>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="是否全职" prop="rider_job" required>
							<el-radio-group v-model="ruleRiderForm.rider_job">
								<el-radio :label="1">全职</el-radio>
								<el-radio :label="2">兼职</el-radio>
							</el-radio-group>
						</el-form-item>
						<el-form-item label="所属区域" prop="region" required>
							<elui-china-area-dht v-model="ruleRiderForm.region"
								@change="handleChangeRegion"></elui-china-area-dht>
						</el-form-item>
						<el-form-item label="联系地址" prop="rider_address" required>
							<el-input v-model.trim="ruleRiderForm.rider_address" clearable placeholder="请输入联系地址" />
						</el-form-item>
						<el-form-item label="经度" prop="lng" required>
							<el-input v-model.trim="ruleRiderForm.lng" clearable placeholder="请输入经度" />
							<el-button style="margin-left:20px" type="primary" @click="handleLon">获取经纬度</el-button>
						</el-form-item>
						<el-form-item label="纬度" prop="lat" required>
							<el-input v-model.trim="ruleRiderForm.lat" clearable placeholder="请输入纬度" />
						</el-form-item>
						<el-form-item label="身份证反面" prop="card_back" required>

							<div class="avatar-uploaderqishou" @click="onKey('card_back')">
								<el-upload ref="uploadFileRef" :show-file-list="false" :action="actionImgUrl()"
									:on-change="fileChange" :multiple="upload_batch" :auto-upload="false" :limit="1"
									style="margin-right: 12px">
									<img v-if="ruleRiderForm.card_back" :src="proxy.imgUrl + ruleRiderForm.card_back"
										class="avatar" />
									<el-icon v-else color="#999" class="avatar-uploader-icon">
										<upload-filled />
									</el-icon>
								</el-upload>
							</div>
						</el-form-item>
					</el-col>
				</el-row>

				<el-form-item>
					<div class="flexs" style="margin-top: 30px">
						<el-button type="primary" :loading="rider_loading" @click="submitRiderForm(ruleRiderRef)">
							确认
						</el-button>
						<el-button @click="resetRiderForm(ruleRiderRef)">重置</el-button>
					</div>
				</el-form-item>
			</el-form>
		</el-dialog>

		<el-dialog v-model="showCoupon" title="发放优惠券" width="600px" :append-to-body="true" :destroy-on-close="true"
			:close-on-click-modal="false" @close="closeAddCoupon">
			<el-form ref="ruleCouponRef" :model="ruleCouponForm" :rules="ruleCheckCoupon" label-width="120px">
				<el-form-item label="会员ID" prop="user_id">
					<div>{{ruleCouponForm.user_id}}</div>
				</el-form-item>
				<el-form-item label="优惠券" prop="coupon_id">
					<el-select v-model="ruleCouponForm.coupon_id" clearable placeholder="请选择优惠券">
						<el-option :label="item.title" :value="item.id" v-for="(item, index) in couponList"
							:key="index" />
					</el-select>
				</el-form-item>
				<el-form-item label="发放数量" prop="num">
					<el-input-number v-model="ruleCouponForm.num" :min="1" />
				</el-form-item>


				<el-form-item>
					<div class="flexs" style="margin-top: 30px">
						<el-button type="primary" :loading="rider_loading" @click="submitCouponForm(ruleCouponRef)">
							确认
						</el-button>
						<el-button @click="resetCouponForm(ruleCouponRef)">重置</el-button>
					</div>
				</el-form-item>
			</el-form>
		</el-dialog>

		<el-dialog v-model="showLevel" title="设置会员等级" width="600px" :append-to-body="true" :destroy-on-close="true"
			:close-on-click-modal="false" @close="closeAddLevel">
			<el-form ref="ruleLevelRef" :model="ruleLevelForm" :rules="ruleCheckLevel" label-width="120px">
				<el-form-item label="会员ID" prop="user_id">
					<div>{{ruleLevelForm.user_id}}</div>
				</el-form-item>
				<el-form-item label="会员等级" prop="mlId">
					<el-select v-model="ruleLevelForm.mlId" clearable placeholder="请选择会员等级">
						<el-option :label="item.name" :value="item.mlId" v-for="(item, index) in levelList"
							:key="index" />
					</el-select>
				</el-form-item>


				<el-form-item>
					<div class="flexs" style="margin-top: 30px">
						<el-button type="primary" :loading="rider_loading" @click="submitLevelForm(ruleLevelRef)">
							确认
						</el-button>
						<el-button @click="resetLevelForm(ruleLevelRef)">重置</el-button>
					</div>
				</el-form-item>
			</el-form>
		</el-dialog>

	</div>
</template>

<script setup>
	import {
		getCurrentInstance,
		ref,
		reactive,
		onMounted,
		watch
	} from "vue"
	import OneLoad from "@mixins/one-load"
	import {
		useRouter
	} from "vue-router"
	import {
		Search,
		UploadFilled,
		CloseBold,
		Plus
	} from "@element-plus/icons-vue"
	import GoBack from "@components/GoBack.vue"

	import {
		EluiChinaAreaDht
	} from 'elui-china-area-dht'
	import chinaAreaData from 'china-area-data';

	import UploadImg from "@mixins/upload-img"

	const router = useRouter()
	const {
		proxy
	} = getCurrentInstance()

	getCoupon()
	getLevel()
	onMounted(() => {
		getList()

	})
	/**
	 * minxin列表加载
	 */
	const {
		page,
		pageSizeNum,
		pageSize,
		loading,
		arr_data,
		totalNums,
		search_text,
		search_btn,
		pubParams,
		pubRefreshParams,
		getdata
	} = OneLoad()
	const type_id = ref("")

	// 切换每页显示条数
	watch(pageSize, (val) => {
		page.value = 1
		pubParams(getList)
	})
	// 跳转第几页
	watch(page, (val) => {
		pubParams(getList)
	})
	
	const sortTab=(e)=>{
		console.log("sortTab",e)
		if(e.prop=='total'){
			total_sort.value=e.order=="ascending"?'asc':e.order=="descending"?'desc':""
		}else if(e.prop=='created_at'){
			created_at_sort.value=e.order=="ascending"?'asc':e.order=="descending"?'desc':""
		}
		pubRefreshParams(getList)
		console.log("arr_data",arr_data)
	}
	const handleSearch = () => {
		search_btn.value = true
		pubRefreshParams(getList)
	}
	const phone = ref('')
	const uid = ref('')
	const is_verifier = ref('')
	const is_distributor = ref('')
	const total_sort=ref('')//消费金额排序；asc:升序；desc:降序
	const created_at_sort=ref('')//注册时间：；asc:升序；desc:降序

	function getList() {
		let params = {
			page: page.value,
			limit: pageSize.value,
			phone: phone.value,
			user_name: search_text.value,
			id: uid.value,
			is_verifier: is_verifier.value,
			is_distributor: is_distributor.value,
			total_sort: total_sort.value,
			created_at_sort: created_at_sort.value
		}
		getdata("admin/member/getMemberList", params)
	}

	const handleDetail = (row) => {
		router.push({
			path: "/MemberDetail",
			query: {
				uid: row.id,
			},
		})
	}

	/*
	 *调余额
	 */
	const showEditBalance = ref(false)
	const form_loading = ref(false)
	const classType = ref(1)
	const ruleClassRef = ref(null)
	const ruleClassForm = reactive({
		type: 1, //1，添加，2减少
		member_id: 0,
		balanceKey: "wallet_balance", //钱包wallet_balance 积分integral_balance
		balance: "",
		remark: "",
		wallet: 0,
		integral: 0,
	})
	const ruleCheckClass = reactive({
		balance: [{
			required: true,
			message: "请输入变动金额",
			trigger: "blur"
		}],
		remark: [{
			required: true,
			message: "请输入备注",
			trigger: "blur"
		}],
	})
	const handleEdit = (row, key) => {
		ruleClassForm.member_id = row.id
		ruleClassForm.wallet = row.wallet_balance
		ruleClassForm.integral = row.integral_balance

		ruleClassForm.balanceKey = key
		showEditBalance.value = true
	}

	const resetClassForm = (formEl) => {
		if (!formEl) return
		formEl.resetFields()
	}
	const closeAddClass = () => {
		showEditBalance.value = false
		resetClassForm(ruleClassRef.value)
	}
	const submitClassForm = (formEl) => {
		if (!formEl) return
		formEl.validate((valid, fields) => {
			if (valid) {
				form_loading.value = true
				// let names = proxy.$util.replaceStr(ruleClassForm.name)
				let data = {
					member_id: ruleClassForm.member_id,
					type: ruleClassForm.type,
					remark: ruleClassForm.remark
				}
				data[`${ruleClassForm.balanceKey}`] = ruleClassForm.balance

				proxy.$axios
					.post("admin/member/saveMemberBalance", data)
					.then((res) => {
						form_loading.value = false
						if (res.data.code == 0) {
							showEditBalance.value = false
							proxy.$message({
								message: "修改成功",
								type: "success"
							})
							pubParams(getList)
						} else {
							proxy.$message({
								message: res.data.msg,
								type: "error"
							})
						}
					})
					.catch((err) => {
						form_loading.value = false
					})
			}
		})
	}

	/*
	 *调佣金
	 */
	const showEditCommission = ref(false)
	const ruleCommissionRef = ref(null)
	const ruleCommissionForm = reactive({
		member_id: 0,
		balance: "",
		remark: "",
	})
	const ruleCheckCommission = reactive({
		balance: [{
			required: true,
			message: "请输入变动金额",
			trigger: "blur"
		}],
		remark: [{
			required: true,
			message: "请输入备注",
			trigger: "blur"
		}],
	})
	const handleCommission = (row, key) => {
		ruleCommissionForm.member_id = row.id
		showEditCommission.value = true
	}

	const resetCommissionForm = (formEl) => {
		if (!formEl) return
		formEl.resetFields()
	}
	const closeAddCommission = () => {
		showEditCommission.value = false
		resetCommissionForm(ruleCommissionRef.value)
	}
	const submitCommissionForm = (formEl) => {
		if (!formEl) return
		formEl.validate((valid, fields) => {
			if (valid) {
				form_loading.value = true
				// let names = proxy.$util.replaceStr(ruleClassForm.name)
				let data = {
					member_id: ruleCommissionForm.member_id,
					commission: ruleCommissionForm.balance,
					remark: ruleCommissionForm.remark
				}

				proxy.$axios
					.post("admin/commission/price/edit", data)
					.then((res) => {
						form_loading.value = false
						if (res.data.code == 0) {
							showEditCommission.value = false
							proxy.$message({
								message: "修改成功",
								type: "success"
							})
							pubParams(getList)
						} else {
							proxy.$message({
								message: res.data.msg,
								type: "error"
							})
						}
					})
					.catch((err) => {
						form_loading.value = false
					})
			}
		})
	}

	function handleDelete(params) {
		proxy.$axios
			.get("admin/store/del", {
				params: {
					id: params.id,
				}
			})
			.then((res) => {
				if (res.data.code == 0) {
					proxy.$message({
						message: "操作成功",
						type: "success"
					})
					pubParams(getList)
				} else {
					proxy.$message({
						message: res.data.msg,
						type: "error"
					})
				}
			})
			.catch((err) => {})
	}

	/*
	 *设置骑手
	 */
	const showRider = ref(false)
	const rider_loading = ref(false)
	const riderType = ref(1)
	const ruleRiderRef = ref(null)
	const ruleRiderForm = reactive({
		rider_job: 1, //1全职，2兼职
		member_id: 0,
		account: "",
		password: "",
		rider_name: "",
		phone: "",
		card_front: "",
		region: [],
		rider_address: "",
		lng: "",
		lat: "",
		card_back: "",

	})
	const ruleCheckRider = reactive({
		account: [{
			required: true,
			message: "请输入账号",
			trigger: "blur"
		}],
		password: [{
			required: true,
			message: "请输入密码",
			trigger: "blur"
		}],
		rider_name: [{
			required: true,
			message: "请输入姓名",
			trigger: "blur"
		}],
		rider_job: [{
			required: true,
			message: "请选择是否全职",
			trigger: "change"
		}],
		region: [{
			required: true,
			message: "请选择区域",
			trigger: "change"
		}],
		rider_address: [{
			required: true,
			message: "请输入联系地址",
			trigger: "blur"
		}],
		lat: [{
			required: true,
			message: "请输入纬度",
			trigger: "blur"
		}],
		lng: [{
			required: true,
			message: "请输入经度",
			trigger: "blur"
		}],
		phone: [{
			validator: proxy.$util.validPhone,
			trigger: "blur"
		}],
		card_front: [{
			required: true,
			message: "请上传身份证正面",
			trigger: "change"
		}],
		card_back: [{
			required: true,
			message: "请上传身份证反面",
			trigger: "change"
		}],
	})

	//省市区
	const regionName = ref("")
	const handleChangeRegion = (e) => {
		regionName.value = chinaAreaData['86'][e[0]] + chinaAreaData[e[0]][e[1]] + chinaAreaData[e[1]][e[2]]
	}

	function handleLon() {
		window.open("https://lbs.qq.com/getPoint/");
	}

	const handleRider = (row, key) => {
		ruleRiderForm.member_id = row.id
		showRider.value = true
	}

	const resetRiderForm = (formEl) => {
		if (!formEl) return
		formEl.resetFields()
	}
	const closeAddRider = () => {
		showRider.value = false
		resetRiderForm(ruleRiderRef.value)
	}
	const submitRiderForm = (formEl) => {
		if (!formEl) return
		formEl.validate((valid, fields) => {
			if (valid) {
				rider_loading.value = true
				// let names = proxy.$util.replaceStr(ruleRiderForm.name)
				let data = {
					member_id: ruleRiderForm.member_id,
					account: ruleRiderForm.account,
					password: ruleRiderForm.password,
					rider_name: ruleRiderForm.rider_name,
					phone: ruleRiderForm.phone,
					rider_job: ruleRiderForm.rider_job,
					card_front: ruleRiderForm.card_front,
					card_back: ruleRiderForm.card_back,
					lat: ruleRiderForm.lat,
					lng: ruleRiderForm.lng,

					rider_province: ruleRiderForm.region[0],
					rider_city: ruleRiderForm.region[1],
					rider_area: ruleRiderForm.region[2],
					rider_address: ruleRiderForm.rider_address,

					pca_label: regionName.value


				}

				proxy.$axios
					.post("admin/rider/setRider", data)
					.then((res) => {
						rider_loading.value = false
						if (res.data.code == 0) {
							showRider.value = false
							proxy.$message({
								message: "设置成功",
								type: "success"
							})
							pubParams(getList)
						} else {
							proxy.$message({
								message: res.data.msg,
								type: "error"
							})
						}
					})
					.catch((err) => {
						rider_loading.value = false
					})
			}
		})
	}

	//发放优惠券
	const couponList = ref([])
	const showCoupon = ref(false)
	const coupon_loading = ref(false)
	const couponType = ref(1)
	const ruleCouponRef = ref(null)
	const ruleCouponForm = reactive({
		user_id: 0,
		num: 1,
		coupon_id: ""

	})
	const ruleCheckCoupon = reactive({
		num: [{
			required: true,
			message: "请输入发放数量",
			trigger: "blur"
		}],
		coupon_id: [{
			required: true,
			message: "请选择优惠券",
			trigger: "change"
		}]
	})
	const handleCoupon = (row) => {
		ruleCouponForm.user_id = row.id
		showCoupon.value = true
	}

	function getCoupon() {
		proxy.$axios
			.get("admin/coupon/all")
			.then((res) => {
				rider_loading.value = false
				if (res.data.code == 0) {
					couponList.value = res.data.data
				} else {
					proxy.$message({
						message: res.data.msg,
						type: "error"
					})
				}
			})
			.catch((err) => {
				rider_loading.value = false
			})
	}

	const resetCouponForm = (formEl) => {
		if (!formEl) return
		formEl.resetFields()
	}
	const closeAddCoupon = () => {
		showCoupon.value = false
		resetCouponForm(ruleCouponRef.value)
	}
	const submitCouponForm = (formEl) => {
		if (!formEl) return
		formEl.validate((valid, fields) => {
			if (valid) {
				coupon_loading.value = true
				// let names = proxy.$util.replaceStr(ruleRiderForm.name)
				let data = {
					user_id: ruleCouponForm.user_id,
					num: ruleCouponForm.num,
					coupon_id: ruleCouponForm.coupon_id,
				}

				proxy.$axios
					.post("admin/send/coupon", data)
					.then((res) => {
						coupon_loading.value = false
						if (res.data.code == 0) {
							showCoupon.value = false
							proxy.$message({
								message: "发放成功",
								type: "success"
							})
						} else {
							proxy.$message({
								message: res.data.msg,
								type: "error"
							})
						}
					})
					.catch((err) => {
						coupon_loading.value = false
					})
			}
		})
	}


	/**
	 * 上传图片
	 * @property {Function} uploadImg 上传
	 */
	const {
		actionImgUrl
	} = UploadImg()
	const imgkey = ref('card_back')
	const onKey = (key) => {
		imgkey.value = key
	}
	const uploadFileRef = ref(null)

	function fileChange(file, fileArr) {
		loading.value = true
		let data = new FormData()
		data.append("file", file.raw)
		proxy.$axios
			.post("admin/upload/upload", data)
			.then((res) => {
				if (res.data.code == 0) {
					var key = imgkey.value
					loading.value = false
					uploadFileRef.value.clearFiles()
					ruleRiderForm[`${key}`] = res.data.data.pic
					console.log("ruleRiderForm", ruleRiderForm)
				} else {
					proxy.$message({
						message: res.data.msg,
						type: "error"
					})
				}
			})

	}
	//设置分销商
	function changeDistributor(row, e) {
		proxy.$axios
			.post("admin/member/distributor/edit", {
				id: row.id,
				is_distributor: e
			})
			.then((res) => {
				if (res.data.code == 0) {
					proxy.$message({
						message: "操作成功",
						type: "success"
					})
					// pubParams(getList)
				} else {
					proxy.$message({
						message: res.data.msg,
						type: "error"
					})
				}
			})
			.catch((err) => {})
	}

	//设置核销员
	function changeVerifier(row, e) {
		proxy.$axios
			.post("admin/member/verifier/edit", {
				id: row.id,
				is_verifier: e
			})
			.then((res) => {
				if (res.data.code == 0) {
					proxy.$message({
						message: "操作成功",
						type: "success"
					})
					// pubParams(getList)
				} else {
					proxy.$message({
						message: res.data.msg,
						type: "error"
					})
				}
			})
			.catch((err) => {})
	}

	//会员等级
	const levelList = ref([])

	function getLevel() {
		proxy.$axios
			.get("admin/membershipLevel/list?limit=1000000")
			.then((res) => {
				rider_loading.value = false
				if (res.data.code == 0) {
					levelList.value = res.data.data.data
				} else {
					proxy.$message({
						message: res.data.msg,
						type: "error"
					})
				}
			})
			.catch((err) => {
				rider_loading.value = false
			})
	}

	const showLevel = ref(false)
	const Level_loading = ref(false)
	const LevelType = ref(1)
	const ruleLevelRef = ref(null)
	const ruleLevelForm = reactive({
		user_id: 0,
		mlId: ""

	})
	const ruleCheckLevel = reactive({
		mlId: [{
			required: true,
			message: "请选择会员等级",
			trigger: "change"
		}]
	})
	const handleLevel = (row) => {
		ruleLevelForm.user_id = row.id
		showLevel.value = true
	}

	const resetLevelForm = (formEl) => {
		if (!formEl) return
		formEl.resetFields()
	}
	const closeAddLevel = () => {
		showLevel.value = false
		resetLevelForm(ruleLevelRef.value)
	}
	const submitLevelForm = (formEl) => {
		if (!formEl) return
		formEl.validate((valid, fields) => {
			if (valid) {
				rider_loading.value = true
				// let names = proxy.$util.replaceStr(ruleRiderForm.name)
				let data = {
					member_id: ruleLevelForm.user_id,
					mlId: ruleLevelForm.mlId,
				}

				proxy.$axios
					.post("admin/membershipLevel/edit", data)
					.then((res) => {
						rider_loading.value = false
						if (res.data.code == 0) {
							showLevel.value = false
							proxy.$message({
								message: "调整成功",
								type: "success"
							})
							pubParams(getList)
						} else {
							proxy.$message({
								message: res.data.msg,
								type: "error"
							})
						}
					})
					.catch((err) => {
						rider_loading.value = false
					})
			}
		})
	}

	// 设置上级
	const handleBind = (row) => {
		router.push({
			path: "/SetBind",
			query: {
				uid: row.id,
			},
		})
	}
	//查看下级
	const handleDownuser=(row)=>{
		router.push({
			path: "/DownUser",
			query: {
				uid: row.id,
			},
		})
	}
</script>

<style lang="less" scoped>
	.user_logo {
		width: 60px;
		height: 60px;
		border-radius: 60px;
	}
</style>

<style>
	.avatar-uploaderqishou .el-upload {
		border: 1px dashed var(--el-border-color);
		border-radius: 6px;
		cursor: pointer;
		position: relative;
		overflow: hidden;
		transition: var(--el-transition-duration-fast);
	}

	.avatar-uploaderqishou .el-upload:hover {
		border-color: var(--el-color-primary);
	}

	.avatar-uploaderqishou .el-icon.avatar-uploader-icon {
		font-size: 28px;
		color: #8c939d;
		width: 178px;
		height: 178px;
		text-align: center;
	}
</style>